package com.xinchili.autoddl.autoClass.config;

import com.xinchili.autoddl.autoClass.processor.EntityProcessor;
import com.xinchili.autoddl.autoClass.properties.EntityScanProperties;
import com.xinchili.autoddl.autoClass.resolver.AbstractDdlResolver;
import com.xinchili.autoddl.autoClass.strategy.ColumnCommentResolver;
import com.xinchili.autoddl.autoClass.strategy.ColumnNameResolver;
import com.xinchili.autoddl.autoClass.strategy.ColumnTypeResolver;
import com.xinchili.autoddl.autoClass.strategy.TableCommentResolver;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(EntityScanProperties.class)
public class AutoDdlAutoConfiguration {

    // 默认的解析器实现
    @Bean
    @ConditionalOnMissingBean(AbstractDdlResolver.class)
    public AbstractDdlResolver defaultDdlResolver() {
        return new DefaultDdlResolver();
    }

    @Bean
    public EntityProcessor entityProcessor(
            ColumnNameResolver nameResolver,
            ColumnTypeResolver typeResolver,
            TableCommentResolver tableResolver,
            ColumnCommentResolver columnResolver,
            EntityScanProperties properties
    ) {
        return new EntityProcessor(nameResolver, typeResolver, tableResolver, columnResolver, properties);
    }

    // 默认实现类，继承抽象基类但不做任何重写
    private static class DefaultDdlResolver extends AbstractDdlResolver {
        // 这里不需要任何实现，直接使用父类的默认方法
    }
}